class fenxing0:
    def __init__(self):
        self.prebar=None
        self.fx=None
    def oncalc(self,b,timekey=None):
        if self.prebar is not None:
            if self.fx is not None:
                if self.fx<=-1:
                    if b["high"]>self.prebar["high"] and b["low"]>self.prebar["low"] and b["close"]>self.prebar["close"]:
                        self.fx=2
                    else:
                        self.fx = -1
                elif self.fx>=1:
                    if b["high"] < self.prebar["high"] and b["low"] < self.prebar["low"] and b["close"]<self.prebar["close"]:
                        self.fx = -2
                    else:
                        self.fx = 1
            else:
                if b["high"]>self.prebar["high"] and b["low"]>self.prebar["low"] and b["close"]>self.prebar["close"]:
                    self.fx=1
                elif b["high"]<self.prebar["high"] and b["low"]<self.prebar["low"] and b["close"]<self.prebar["close"]:
                    self.fx=-1
        self.prebar=b
        return self.fx

if __name__ == '__main__':
    from jili.core import load, save
    from research.calcor.calcors_graph import graph_calcor
    k1m = load(r"D:\data\k1m_tq\TA109\202105_k1m.pkl")
    from research.calcor.dim2.cross import cross
    fenxing0=fenxing0()
    cc = [{'calc_cmd': 'ta', 'cmd': 'EMA', 'out': ['ema30'], 'input': {'price': 'close'}, 'arg': {'timeperiod': 30},
           'batch': 30},
          {'calc_cmd': 'ta', 'cmd': 'EMA', 'out': ['ema10'], 'input': {'price': 'close'}, 'arg': {'timeperiod': 10},
           'batch': 10},
          {'calc_cmd': 'function', 'function': fenxing0.oncalc, 'out': 'fenxing0', 'input': ["_"]}]
    c = graph_calcor(cc)
    for d, v in k1m.items():
        for t in v:
            t = c.onbar(t)
    print("end")